<?php

namespace App\Models;

use Zizaco\Entrust\EntrustRole;

class Role extends EntrustRole
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'display_name', 'description',
    ];

    /**
     * Give permission to role
     * @param array $permissionId
     */
    public function givePermissionsTo(array $permissionId)
    {
        $this->detachPermissions($this->perms);
        $this->attachPermissionToId($permissionId);
    }

    /**
     * Attach multiple $PermissionsId to a user
     * @param $permissionsId
     */
    public function attachPermissionToId($permissionsId)
    {
        foreach ($permissionsId as $pid) {
            $this->attachPermission($pid);
        }
    }
}
